﻿// This file is part of WifiCC3000 - the Managed Wifi Driver for the TI CC3000
// WifiCC3000 is free software licensed under the Apache License 2.0
// by Valkyrie-MT

using System;
using System.Collections;
using System.Text;

namespace Networking
{
    public class AccessPoint
    {
        public string Ssid { get; set; }
        public string Key { get; set; }
        public WifiSecurityType Security { get; set; }

        //public static implicit operator byte[](AccessPoint c)
        //{
        //    //TODO: convert the AccessPoint to the byte format used in the connect argument

        //    /* sec_type - selects the security options: WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2. */
        //    /* ssid specifies the SSID of the AP, up to 32 bytes and is ASCII. */
        //    /* ssid_len specifies the length of the SSID. */
        //    /* bssid specifies the SSID, up to 6 bytes. */
        //    /* key specifies the key, up to 16 bytes. */
        //    /* key_len specifies the key length. */
        //    /* sec_type selects the security options: WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2. */
        //    /* On success, zero is returned. On error, negative is returned. Note that even though a zero is returned on success to trigger connection operation, it does not mean that CCC3000 is already connected.
        //     An asynchronous "Connected" event is generated upon the finish of connection process. */

        //    // Fill in command buffer
        //    //args = UINT32_TO_STREAM(args, 0x0000001c);
        //    //args = UINT32_TO_STREAM(args, ssid_len);
        //    //args = UINT32_TO_STREAM(args, ulSecType);
        //    //args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
        //    //args = UINT32_TO_STREAM(args, key_len);
        //    //args = UINT16_TO_STREAM(args, 0);

        //    //// padding shall be zeroed
        //    //if (bssid)
        //    //{
        //    //    ARRAY_TO_STREAM(args, bssid, ETH_ALEN);
        //    //}
        //    //else
        //    //{
        //    //    ARRAY_TO_STREAM(args, bssid_zero, ETH_ALEN);
        //    //}

        //    //ARRAY_TO_STREAM(args, ssid, ssid_len);

        //    //if (key_len && key)
        //    //{
        //    //    ARRAY_TO_STREAM(args, key, key_len);
        //    //}
        //    c.Ssid = c.Ssid.Length > 32 ? c.Ssid.Substring(0, 32) : c.Ssid;  // trim!  
        //    c.Key = c.Key.Length > 16 ? c.Key.Substring(0, 16) : c.Key;

        //    var args = new ArrayList();
            
        //    args.AddRange(0x0000001c.ToBytesRev());
        //    args.AddRange(
        //    //args = UINT32_TO_STREAM(args, ssid_len);
        //    //args = UINT32_TO_STREAM(args, ulSecType);
        //    //args = UINT32_TO_STREAM(args, 0x00000010 + ssid_len);
        //    //args = UINT32_TO_STREAM(args, key_len);
        //    //args = UINT16_TO_STREAM(args, 0);




        //    return new byte[0];
        //}
    }

    public class AccessPointResult : AccessPoint
    {

        public sbyte SignalStrength { get; set; }
        public byte[] MacAddress { get; set; }

    }

    public enum WifiSecurityType : uint
    {
        Open = 0, WEP = 1, WPA = 2, WPA2 = 3
    }

}
